import '../app_configure.dart';
import 'device_data_base.dart';

class DeviceDataV70 extends DevcieDataBase {
  final List<int> datas = [0xB4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5A]; //对码
  final List<int> cdats = [0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F]; //控制

  DeviceData70() {
    fillAppId();
  }

  @override
  void fillAppId() {
    datas[1] = AppConfig.instance.appId & 0xFF;
    datas[2] = (AppConfig.instance.appId >> 8) & 0xFF;

    cdats[1] = AppConfig.instance.appId & 0xFF;
    cdats[2] = (AppConfig.instance.appId >> 8) & 0xFF;
  }

  @override
  List<int> getPair() {
    return datas;
  }

  @override
  List<int> getStopPair() {
    cdats[3] = 0x00;
    cdats[4] = 0x00;
    return cdats;
  }

  @override
  List<int> getSpeed(int i) {
    cdats[4] = 0xFF & i;
    return cdats;
  }

  @override
  List<int> getDirection(int i) {
    cdats[3] = 0xFF & i;
    return cdats;
  }

  @override
  List<int> getDataAt(int index, int value) {
    if (index < 0 || index > (cdats.length - 1)) {
      return cdats;
    }
    cdats[index] = 0xFF & value;
    return cdats;
  }

  @override
  List<int> actionStop() {
    cdats[3] = 0x00;
    cdats[4] = 0x00;
    return cdats;
  }

//前进
  @override
  List<int> actionForward({bool reverse = false, double ratio = 1}) {
    if (reverse) {
      getDataAt(3, 0x70);
      return getDataAt(4, 0x7);
    }
    getDataAt(3, 0xf0);
    return getDataAt(4, 0xf);
  }

  //后退
  @override
  List<int> actionBackward({bool reverse = false, double ratio = 1}) {
    if (reverse) {
      getDataAt(3, 0xf0);
      return getDataAt(4, 0xf);
    }
    getDataAt(3, 0x70);
    return getDataAt(4, 0x7);
  }

  //左转
  @override
  List<int> actionLeft({bool reverse = false, double ratio = 1}) {
    if (reverse) {
      return getDataAt(4, 0x7);
    }
    return getDataAt(3, 0x70);
  }

  //右转
  @override
  List<int> actionRight({bool reverse = false, double ratio = 1}) {
    if (reverse) {
      return getDataAt(3, 0x70);
    }
    return getDataAt(4, 0x7);
  }

  //左转前进
  @override
  List<int> actionForwardLeft(
      {bool verticalReverse = false, bool horizontalReverse = false}) {
    if (verticalReverse) {
      getDataAt(3, 0x40);
      return getDataAt(4, 0x7);
    }
    getDataAt(4, 0x04);
    return getDataAt(3, 0x70);
  }

  //右转前进
  @override
  List<int> actionForwardRight(
      {bool verticalReverse = false, bool horizontalReverse = false}) {
    if (verticalReverse) {
      getDataAt(3, 0x70);
      return getDataAt(4, 0x4);
    }
    getDataAt(4, 0x07);
    return getDataAt(3, 0x40);
  }

  //左转后退
  @override
  List<int> actionBackwardLeft(
      {bool verticalReverse = false, bool horizontalReverse = false}) {
    if (verticalReverse) {
      getDataAt(3, 0xf0);
      return getDataAt(4, 0xb);
    }
    getDataAt(4, 0x0f);
    return getDataAt(3, 0xb0);
  }

  //右转后退
  @override
  List<int> actionBackwardRight(
      {bool verticalReverse = false, bool horizontalReverse = false}) {
    if (verticalReverse) {
      getDataAt(4, 0x0f);
      return getDataAt(3, 0xb0);
    }
    getDataAt(3, 0xf0);
    return getDataAt(4, 0xb);
  }
}

/**
//=======================//
功能说明：
用到的是电机A和电机D
前进 rfbuf[3] = 0xF0;
后退 rfbuf[3] = 0x70;
停止 rfbuf[3] = 0x00;
左转 rfbuf[4] = 0x0F;
右转 rfbuf[4] = 0x07;
停止 rfbuf[4] = 0x00;
//=======================//
APP对码长度 ：8
APP对码数据
rfbuf[0] = 0xB4;
rfbuf[1] = ID_0;
rfbuf[2] = ID_1;
rfbuf[3] = 0x0;
rfbuf[4] = 0x0;
rfbuf[5] = 0x0;
rfbuf[6] = 0x0;
rfbuf[7] = 0x5A;
//=======================//
APP控制长度 ：8
rfbuf[0] = 0xC0;
rfbuf[1] = ID_0;
rfbuf[2] = ID_1;
rfbuf[3] = 
rfbuf[4] = 
rfbuf[5] = 0x0;
rfbuf[6] = 0x0;
rfbuf[7] = 0x3F;	

1档：rfbuf[0] = 0xC0;rfbuf[7] = 0x3F;	
2档：rfbuf[0] = 0xC1;rfbuf[7] = 0x3E;
3档：rfbuf[0] = 0xC2;rfbuf[7] = 0x3D;
4档：rfbuf[0] = 0xC3;rfbuf[7] = 0x3C;
控制数据说明：
data[3]
[bit7] 1：电机A正转，0:电机A反转
[bit6~bit4] 电机A速度，0为停止
[bit3] 1：电机B正转，0:电机B反转
[bit2~bit0] 电机B速度，0为停止

data[4]
[bit7] 1：电机C正转，0:电机C反转
[bit6~bit4] 电机C速度，0为停止
[bit3] 1：电机D正转，0:电机D反转
[bit2~bit0] 电机D速度，0为停止
//=======================//
注：可参考积木盒子APP，控制数据长度不同，头码不同

 */